clean__get_town_hs<-function(data,year){
  data_full<-data
  
  data<- as.data.frame(data_full %>% group_by(judet_bac,unitate_de_invatamant,town_hs_bac,an) %>% summarize() %>% ungroup())
  
  #Get town directly, when preceded by "city", "town", "village", etc
  data[grepl(".+,", data$unitate_de_invatamant),]$town_hs_bac<-sub(".+,", "", data$unitate_de_invatamant)[grepl(".+,", data$unitate_de_invatamant)]
  replace_string<-paste0(".+( ORASUL )|.+( COM )|.+( ORAS )|.+( MUNICIPIUL )|.+( LOC )|.+( LOCALITATEA )|",
                         ".+( \\(ENERGETIC\\) )|.+( \\(AUTO\\) )|.+( \\(EC\\. TEODOROIU\\) )|.+( ECONOMIC\\, ADMINISTRATIV SI DE SERVICII )|",
                         ".+( LOC. )|.+( MUN. )|.+( SAT )|.+( COMUNA )|.+( ORAȘ )|.+( MUN )|.+( COM\\. )|.+\" |.+\\d |.+\", |.+\"")
  data[grepl(replace_string, data$unitate_de_invatamant),]$town_hs_bac<-sub(replace_string, "", data[grepl(replace_string, data$unitate_de_invatamant),]$unitate_de_invatamant)
  #Get town for remaining obervations
  replace_string<-paste0(".+( TEHNOLOGIC DE TURISM SI ALIMENTATIE )|.+( MARMATIA )|.+( AL BANATULUI MONTAN )|",
                         ".+( PARTICULAR )|.+( DE ARTA )|.+( DEFICIENTI DE VEDERE )|.+( BILINGV ROMINO-CROAT )|",
                         ".+( DE CONSTRUCTII SI PROTECTIA MEDIULUI )|.+( PROFESIONALA DE COOPERATIE )|",
                         ".+( DE PROTECTIA MEDIULUI  )|.+( WALDORF )|(FEG )|.+( DE VEST )|",
                         ".+( PENTRU EDUCATIE INCLUZIVA )|.+( DE ARTE SI MESERII )|",
                         ".+( CONSTR. CAI FERATE )|.+( DE CHIMIE INDUSTRIALA )|",
                         ".+( CONSTRUCTII MONTAJ )|.+( INDUSTRIAL MINIER )|.+( MINIER )|",
                         ".+( DE COOPERATIE )|.+( INDUSTRIE USOARA )|.+( ECONOMIC-ADMINISTRATIV)|",
                         ".+( MESERII SI SERVICII )|.+( INDUSTRIE MICA SI SERVICII )|.+( NATIONALA DE GAZ )|",
                         ".+( DE MUZICA SI ARTE PLASTICE )|.+( CU PROGRAM DE ATLETISM )|.+( DE MUZICA )|",
                         ".+( ADMINISTRATIV SI DE SERVICII )|.+( ALIMENTATIE PUBLICA )|.+( CU PROGRAM SPORTIV )|",
                         ".+( FORESTIER )|.+( INDUSTRIA STICLEI )|.+( COOPERATIST )|.+( COOPERATIE )|",
                         ".+( DE MARINA )|.+( DE AGRICULTURA SI ECONOMIE )|.+( CONSTRUCTII CAI FERATE )|",
                         ".+( DE TRANSPORTURI AUTO )|.+( BILINGV ROMANO-CROAT )|.+( TEHNIC DE TRANSPORTURI )|",
                         ".+( SPECIAL PENTRU DEFICIENTI DE AUZ )|.+( ADVENTIST )|",
                         ".+( TRANSPORTURI CAI FERATE )|.+( VOCATIONAL DE ARTA )|.+( ROMANO-CATOLIC )|.+( SPECIAL )|.+( AUTO )|",
                         ".+( SILVIC )|.+( TEHNIC )|.+( CONSTRUCTII DE MASINI )|.+( METALURGIC )|.+( PETROL )|",
                         ".+( BANATEAN )|.+( CARASAN )|.+( ALIMENTARA )|.+( PENTICOSTAL )|.+( BAPTIST )|.+( AGRICOL )|.+( DE AFACERI )|",
                         ".+( REFORMAT )|.+( TEOLOGIC )|.+( ORTODOX )|.+( TEHNOLOGIC FORESTIER )|.+( TEHNOLOGIC CONSTRUCTII DE MASINI )|",
                         ".+( SPORTIV )|.+( SANITAR )|.+( ENERGETIC )|.+( TEHNOLOGIC )|.+( PEDAGOGIC )|.+( TEORETIC )|",
                         ".+( DE INFORMATICA )|.+( ECONOMIC )|.+( TRANSPORTURI )|.+( ADMINISTRATIV )|.+( DE TURISM )|.+( PENTRU TRANSPORT RUTIER )|",
                         ".+( MAGHIARA )|.+( TELECOMUNICATII )|.+( DE ARTE )|.+( CONSTRUCTII )|.+( SERVICII )|.+( AUTOMECANICA )|.+( NATIONAL )|",
                         ".+( FEROVIAR )|.+( TEXTIL )|(GR. SC. )|(CENTRUL SCOLAR )|(GRUP SCOLAR INDUSTRIAL )|",
                         ".+(THE CAMBRIDGE INTERNATIONAL SCHOOL IN )|.+( DIN )|(GRI )|(GRUP SCOLAR )|(GRUPUL SCOLAR INDUSTRIAL )|(GRUPUL SCOLAR )|(LICEUL )") 
  data[grepl(replace_string, data$unitate_de_invatamant) & is.na(data$town_hs_bac),]$town_hs_bac<-
    sub(replace_string, "", data[grepl(replace_string,data$unitate_de_invatamant) & is.na(data$town_hs_bac),]$unitate_de_invatamant)
  
  


  


  if (year==2016){
    data$town_hs_bac<-if_else(data$judet_bac=='GIURGIU' & grepl("MIRON NICOLESCU",data$unitate_de_invatamant),"GIURGIU",data$town_hs_bac)
  }
  if (year==2008){

    }
    
    data$town_hs_bac<-if_else(data$judet_bac=='BUZAU' & grepl("ALEXANDRU MARGHILOMAN",data$unitate_de_invatamant),"BUZAU",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='BACAU' & grepl("BC",data$unitate_de_invatamant),"BACAU",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='BIHOR' & grepl(" STEI",data$unitate_de_invatamant),"STEI",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='COVASNA' & grepl("INT\\. BUZAULUI",data$unitate_de_invatamant),"INTORSURA BUZAULUI",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='DOLJ' & grepl("MOFLENI",data$unitate_de_invatamant),"CRAIOVA",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='CLUJ' & grepl("GHERLA",data$unitate_de_invatamant),"GHERLA",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='CONSTANTA' & grepl("M. KOGALNICEANU",data$town_hs_bac),"MIHAIL KOGALNICEANU",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='CONSTANTA' & grepl("CALLATIS",data$town_hs_bac),"MANGALIA",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='GALATI' & grepl("PAUL DIMO",data$unitate_de_invatamant),"GALATI",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='IASI' & grepl("NICOLINA",data$unitate_de_invatamant),"IASI",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='IASI' & grepl("DEFICIENTI DE VEDERE",data$unitate_de_invatamant),"TARGU FRUMOS",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='MEHEDINTI' & grepl("DE MARINA",data$town_hs_bac),"ORSOVA",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='MEHEDINTI' & grepl("AUTO",data$town_hs_bac),"DROBETA-TURNU SEVERIN",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='SIBIU' & grepl("AVRIG",data$unitate_de_invatamant),"AVRIG",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='SIBIU' & grepl("BETANIA",data$unitate_de_invatamant),"SIBIU",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='VALCEA' & grepl("RM",data$unitate_de_invatamant),"RAMNICU VALCEA",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='VALCEA' & grepl("BABENI",data$unitate_de_invatamant),"BABENI",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='VALCEA' & grepl("BAILE OLANESTI",data$unitate_de_invatamant),"BAILE OLANESTI",data$town_hs_bac)

    
    #2009
    if (year==2009){
      data$town_hs_bac<-if_else(data$judet_bac=='MEHEDINTI' & grepl("AUTO",data$town_hs_bac),"DROBETA-TURNU SEVERIN",data$town_hs_bac)
      data$town_hs_bac<-if_else(data$judet_bac=='MEHEDINTI' & grepl("DE MARINA",data$town_hs_bac),"ORSOVA",data$town_hs_bac)
      data$town_hs_bac<-if_else(data$judet_bac=='DOLJ' & (grepl("ION MINCU",data$town_hs_bac)),"CRAIOVA",data$town_hs_bac)
    }
    
    if (year==2013){
      data$town_hs_bac<-if_else(data$judet_bac=='IALOMITA' & grepl("SCINTEIA",data$town_hs_bac),"SCANTEIA",data$town_hs_bac)
      data$town_hs_bac<-gsub('SANGERU','SINGERU',data$town_hs_bac)
      data$town_hs_bac<-if_else(data$judet_bac=='MARAMURES' & grepl("SPORTIV",data$town_hs_bac),"BAIA MARE",data$town_hs_bac)
      
    }
  
  if (year==2014){
    data$town_hs_bac<-if_else(data$judet_bac=='HUNEDOARA' & grepl("LUPENI",data$town_hs_bac),"LUPENI",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('TRAIAN',data$unitate_de_invatamant) & grepl('MEHEDINTI',data$judet_bac),"DROBETA-TURNU SEVERIN",data$town_hs_bac)
    
    
  }
  
  
  if (year==2018){
    data$town_hs_bac<-if_else(data$judet_bac=='IASI' & grepl("WALDORF",data$town_hs_bac),"IASI",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='IASI' & grepl("COLEGIUL NATIONAL,",data$town_hs_bac),"IASI",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='NEAMT' & grepl("VINATORI",data$unitate_de_invatamant),"VANATORI NEAMT",data$town_hs_bac)
  
    data$town_hs_bac<-if_else(data$judet_bac=='MEHEDINTI' & grepl("TRAIAN",data$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data$town_hs_bac)
    
    data$town_hs_bac<-if_else(data$judet_bac=='MEHEDINTI' & grepl("COLEGIUL TEHNIC DE TRANSPORTURI AUTO",data$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data$town_hs_bac)
    
    }
  
  if (year==2019){
    data$town_hs_bac<-if_else(grepl('CURTEA DE ARGES',data$town_hs_bac),"CURTEA DE ARGES",data$town_hs_bac)
    
    data$town_hs_bac<-if_else(grepl('SEBES',data$town_hs_bac) & grepl('ALBA',data$judet_bac),"SEBES",data$town_hs_bac)
    
    data$town_hs_bac<-if_else(grepl('GEORGE VALSAN',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('ANA ASLAN',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('ION GHICA',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('GHEORGHE MUNTEANU MURGOCI',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('NICOLAE BALCESCU',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('COSTIN D\\. NENITESCU',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('EDMOND NICOLAU',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('PANAIT ISTRATI',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('HARICLEA DARCLEE',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('D\\. P\\. PERPESSICIUS',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('SPORTIV',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('MIHAIL SEBASTIAN',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('NICOLAE IORGA',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('PANAIT CERNA',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('ANGHEL SALIGNY',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('GHEORGHE K\\. CONSTANTINESCU',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('GRIGORE MOISIL',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"BRAILA",data$town_hs_bac)
    
    data$town_hs_bac<-if_else(grepl('NICOLAE ONCESCU',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"IANCA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl('CONSTANTIN ANGELESCU',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"IANCA",data$town_hs_bac)

    data$town_hs_bac<-if_else(grepl('GEORGE VILSAN',data$unitate_de_invatamant) & data$judet_bac=='BRAILA',"FAUREI",data$town_hs_bac)

    data$town_hs_bac<-if_else(grepl('SCOALA PROFESIONALA SIG',data$unitate_de_invatamant) & data$judet_bac=='SALAJ',"SAG",data$town_hs_bac)

    data$town_hs_bac<-if_else(data$unitate_de_invatamant=="LICEUL TEHNOLOGIC" & data$judet_bac=='MEHEDINTI',"DROBETA-TURNU SEVERIN",data$town_hs_bac)

  }
 
    
    
    
    #ADJUSTMENTS BY COUNTY
    names<-unique(data$judet_bac)
    data<-data %>% 
      group_split(judet_bac)
    names(data)<-names
    
    
  
    
    
    
    data[['ALBA']]$town_hs_bac<-if_else(grepl("SEBES",data[['ALBA']]$unitate_de_invatamant),"SEBES",data[['ALBA']]$town_hs_bac)
    
    data[['ARAD']]$town_hs_bac<-if_else(grepl("ADAM MULLER GUTTENBRUNN",data[['ARAD']]$unitate_de_invatamant),"ARAD",data[['ARAD']]$town_hs_bac)
    data[['ARAD']]$town_hs_bac<-if_else(grepl("CONCORD",data[['ARAD']]$unitate_de_invatamant),"ARAD",data[['ARAD']]$town_hs_bac)
    
    data[['ARGES']]$town_hs_bac<-if_else(grepl("ALEXANDRU IONESCU",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac) #2016
    data[['ARGES']]$town_hs_bac<-if_else(data[['ARGES']]$unitate_de_invatamant=="LICEUL TEHNOLOGIC","VEDEA",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("PETRESCU",data[['ARGES']]$unitate_de_invatamant),"STALPENI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("CURTEA",data[['ARGES']]$unitate_de_invatamant),"CURTEA DE ARGES",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("PETRE IONESCU MUSCEL",data[['ARGES']]$unitate_de_invatamant),"DOMNESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("DINU BRATIANU",data[['ARGES']]$unitate_de_invatamant),"STEFANESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("TEIULEANU",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("BRANCUSI",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("DOBRESCU",data[['ARGES']]$unitate_de_invatamant),"CURTEA DE ARGES",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("ELIM",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("DACIA",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("ASTRA",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("DINU LIPATTI",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("VIITORUL",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else((grepl("IUSTIN PATRIARHUL",data[['ARGES']]$unitate_de_invatamant)),"CAMPULUNG",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else((grepl("NEAGOE VODA BASARAB",data[['ARGES']]$unitate_de_invatamant)),"CURTEA DE ARGES",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("MIHALACHE",data[['ARGES']]$unitate_de_invatamant),"TOPOLOVENI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("CANTACUZINO",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("BARBU",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("CAROL",data[['ARGES']]$unitate_de_invatamant),"CAMPULUNG",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("BARBILIAN",data[['ARGES']]$unitate_de_invatamant),"CAMPULUNG",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("NENITESCU",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("ARMAND",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("VLAICU VODA",data[['ARGES']]$unitate_de_invatamant),"CURTEA DE ARGES",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("ION C. BRATIANU",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("REBREANU",data[['ARGES']]$unitate_de_invatamant),"MOZACENI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("SLAVESCU",data[['ARGES']]$unitate_de_invatamant),"RUCAR",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("VITEAZUL",data[['ARGES']]$unitate_de_invatamant),"PITESTI",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("VLAICU VODA",data[['ARGES']]$unitate_de_invatamant),"CURTEA DE ARGES",data[['ARGES']]$town_hs_bac)
    data[['ARGES']]$town_hs_bac<-if_else(grepl("COLIBASI",data[['ARGES']]$unitate_de_invatamant),"MIOVENI",data[['ARGES']]$town_hs_bac)
    
    
    data[['BACAU']]$town_hs_bac<-if_else(grepl("ASACHI",data[['BACAU']]$unitate_de_invatamant),"ONESTI",data[['BACAU']]$town_hs_bac)
    data[['BACAU']]$town_hs_bac<-if_else(grepl("STEFAN CEL MARE",data[['BACAU']]$unitate_de_invatamant),"BACAU",data[['BACAU']]$town_hs_bac)
    
    data[['BOTOSANI']]$town_hs_bac<-if_else((grepl("GRUPUL SCOLAR DE COOPERATIE",data[['BOTOSANI']]$unitate_de_invatamant)),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else((grepl("CENTRUL DE STUDII STEFAN CEL MARE SI SFANT",data[['BOTOSANI']]$unitate_de_invatamant)),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("SPORTIV",data[['BOTOSANI']]$unitate_de_invatamant),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("INDUSTRIE USOARA$",data[['BOTOSANI']]$unitate_de_invatamant),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("ORTODOX",data[['BOTOSANI']]$unitate_de_invatamant) & grepl("SFANTUL GHEORGHE",data[['BOTOSANI']]$unitate_de_invatamant),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("STEFAN LUCHIAN",data[['BOTOSANI']]$unitate_de_invatamant),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("ORTODOX",data[['BOTOSANI']]$unitate_de_invatamant)& (grepl("IOAN IACOB",data[['BOTOSANI']]$unitate_de_invatamant)),"DOROHOI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("PETRU RARES",data[['BOTOSANI']]$unitate_de_invatamant),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("NEGREANU",data[['BOTOSANI']]$unitate_de_invatamant),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("CIUCA",data[['BOTOSANI']]$unitate_de_invatamant),"SAVENI",data[['BOTOSANI']]$town_hs_bac)
    data[['BOTOSANI']]$town_hs_bac<-if_else(grepl("IORGA",data[['BOTOSANI']]$unitate_de_invatamant),"BOTOSANI",data[['BOTOSANI']]$town_hs_bac)
    
    data[['BIHOR']]$town_hs_bac<-if_else(grepl("BOCOCI",data[['BIHOR']]$unitate_de_invatamant),"ORADEA",data[['BIHOR']]$town_hs_bac)
    data[['BIHOR']]$town_hs_bac<-if_else(grepl("SACUIENI",data[['BIHOR']]$unitate_de_invatamant),"SACUENI",data[['BIHOR']]$town_hs_bac)
    data[['BIHOR']]$town_hs_bac<-if_else(grepl("STEI",data[['BIHOR']]$unitate_de_invatamant),"STEI",data[['BIHOR']]$town_hs_bac)
    data[['BIHOR']]$town_hs_bac<-if_else(grepl("CIORDAS",data[['BIHOR']]$unitate_de_invatamant),"BEIUS",data[['BIHOR']]$town_hs_bac)
    
    data[['BISTRITA-NASAUD']]$town_hs_bac<-if_else(grepl("SANITAR",data[['BISTRITA-NASAUD']]$unitate_de_invatamant),"BISTRITA",data[['BISTRITA-NASAUD']]$town_hs_bac)
    data[['BISTRITA-NASAUD']]$town_hs_bac<-if_else(grepl("BISTRTA",data[['BISTRITA-NASAUD']]$unitate_de_invatamant),"BISTRITA",data[['BISTRITA-NASAUD']]$town_hs_bac)
    
    data[['BRAILA']]$town_hs_bac<-if_else(grepl("MATEI BASARAB",data[['BRAILA']]$unitate_de_invatamant),"MAXINENI",data[['BRAILA']]$town_hs_bac)
    
    data[['BRASOV']]$town_hs_bac<-if_else((grepl("DOAMNA STANCA",data[['BRASOV']]$unitate_de_invatamant)),"FAGARAS",data[['BRASOV']]$town_hs_bac)
    data[['BRASOV']]$town_hs_bac<-if_else((grepl("FELDIOARA",data[['BRASOV']]$unitate_de_invatamant)),"FELDIOARA",data[['BRASOV']]$town_hs_bac)
    
    data[['BUZAU']]$town_hs_bac<-if_else(grepl("RADU VLADESCU",data[['BUZAU']]$unitate_de_invatamant),"PATARLAGELE",data[['BUZAU']]$town_hs_bac)
    data[['BUZAU']]$town_hs_bac<-if_else(grepl("DEFICIENTI DE VEDERE",data[['BUZAU']]$unitate_de_invatamant),"BUZAU",data[['BUZAU']]$town_hs_bac)
    data[['BUZAU']]$town_hs_bac<-if_else(grepl("IOLANDA",data[['BUZAU']]$unitate_de_invatamant),"BUZAU",data[['BUZAU']]$town_hs_bac)
    
    data[['CLUJ']]$town_hs_bac<-if_else((grepl("OCTAVIAN STROIA",data[['CLUJ']]$unitate_de_invatamant)),"CLUJ-NAPOCA",data[['CLUJ']]$town_hs_bac)
    data[['CLUJ']]$town_hs_bac<-if_else(grepl("CLUJ-NAPOCA",data[['CLUJ']]$unitate_de_invatamant),"CLUJ-NAPOCA",data[['CLUJ']]$town_hs_bac)
    
    data[['CONSTANTA']]$town_hs_bac<-if_else(grepl("GEORGE CALINESCU",data[['CONSTANTA']]$unitate_de_invatamant),"CONSTANTA",data[['CONSTANTA']]$town_hs_bac)
    data[['CONSTANTA']]$town_hs_bac<-if_else(grepl("EFORIE",data[['CONSTANTA']]$unitate_de_invatamant),"EFORIE",data[['CONSTANTA']]$town_hs_bac)
    data[['CONSTANTA']]$town_hs_bac<-if_else(grepl("HURMUZESCU",data[['CONSTANTA']]$unitate_de_invatamant),"MEDGIDIA",data[['CONSTANTA']]$town_hs_bac)
    
    data[['COVASNA']]$town_hs_bac<-if_else((grepl("BERDE ARON",data[['COVASNA']]$unitate_de_invatamant)),"SFANTU GHEORGHE",data[['COVASNA']]$town_hs_bac)
    
    data[['DOLJ']]$town_hs_bac<-if_else((grepl("ANGHEL SALIGNY",data[['DOLJ']]$unitate_de_invatamant)),"CRAIOVA",data[['DOLJ']]$town_hs_bac)
    data[['DOLJ']]$town_hs_bac<-if_else((grepl("ION MINCU",data[['DOLJ']]$unitate_de_invatamant)),"CRAIOVA",data[['DOLJ']]$town_hs_bac)
    
    data[['GALATI']]$town_hs_bac<-if_else((grepl("DIMITRIE CANTEMIR",data[['GALATI']]$unitate_de_invatamant)),"GALATI",data[['GALATI']]$town_hs_bac)
    
    data[['GORJ']]$town_hs_bac<-if_else((grepl("BILTA",data[['GORJ']]$town_hs_bac)|grepl("RUNCU",data[['GORJ']]$town_hs_bac)),"BILTA, RUNCU",data[['GORJ']]$town_hs_bac)
    data[['GORJ']]$town_hs_bac<-if_else((grepl("ION MINCU",data[['GORJ']]$unitate_de_invatamant)),"TARGU-JIU",data[['GORJ']]$town_hs_bac)
    
    data[['GIURGIU']]$town_hs_bac<-if_else(grepl("TEOCTIST",data[['GIURGIU']]$unitate_de_invatamant),"GIURGIU",data[['GIURGIU']]$town_hs_bac)
    data[['GIURGIU']]$town_hs_bac<-if_else(grepl("MIRON NICOLESCU",data[['GIURGIU']]$unitate_de_invatamant),"GIURGIU",data[['GIURGIU']]$town_hs_bac)
    data[['GIURGIU']]$town_hs_bac<-if_else(grepl("IOAN BALANESCU",data[['GIURGIU']]$unitate_de_invatamant),"GIURGIU",data[['GIURGIU']]$town_hs_bac)
    data[['GIURGIU']]$town_hs_bac<-if_else(grepl("ION BARBU",data[['GIURGIU']]$unitate_de_invatamant),"GIURGIU",data[['GIURGIU']]$town_hs_bac)
    
    
    data[['HUNEDOARA']]$town_hs_bac<-if_else(grepl("HUNEDOARA",data[['HUNEDOARA']]$unitate_de_invatamant),"HUNEDOARA",data[['HUNEDOARA']]$town_hs_bac)
    data[['HUNEDOARA']]$town_hs_bac<-if_else(grepl("LUPENI",data[['HUNEDOARA']]$unitate_de_invatamant),"LUPENI",data[['HUNEDOARA']]$town_hs_bac)
    
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("MARK TWAIN",data[['ILFOV']]$unitate_de_invatamant),"VOLUNTARI",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("HULUBEI",data[['ILFOV']]$unitate_de_invatamant),"MAGURELE",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("DOAMNA CHIAJNA",data[['ILFOV']]$unitate_de_invatamant),"ROSU",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("DUMITRU DUMITRESCU",data[['ILFOV']]$unitate_de_invatamant),"MAGURELE",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("VINTILA BRATIANU",data[['ILFOV']]$unitate_de_invatamant),"DRAGOMIRESTI-VALE",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("ROSETTI",data[['ILFOV']]$unitate_de_invatamant),"VIDRA",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("LALESCU",data[['ILFOV']]$unitate_de_invatamant),"BRANESTI",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("IOAN PETRUS",data[['ILFOV']]$unitate_de_invatamant),"OTOPENI",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("PAMFIL SEICARU",data[['ILFOV']]$unitate_de_invatamant),"CIOROGARLA",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("MIHAIL KOGALNICEANU",data[['ILFOV']]$unitate_de_invatamant),"SNAGOV",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("STIRBEY",data[['ILFOV']]$unitate_de_invatamant),"BUFTEA",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("NICOLAE BALCESCU",data[['ILFOV']]$unitate_de_invatamant),"VOLUNTARI",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("CEZAR NICOLAU",data[['ILFOV']]$unitate_de_invatamant),"BRANESTI",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("FILOFTEIA",data[['ILFOV']]$unitate_de_invatamant),"BRANESTI",data[['ILFOV']]$town_hs_bac)
    data[['ILFOV']]$town_hs_bac<-if_else(grepl("PIETRARU",data[['ILFOV']]$unitate_de_invatamant),"BRANESTI",data[['ILFOV']]$town_hs_bac)
    
    data[['IASI']]$town_hs_bac<-if_else((grepl("SCHEIA",data[['IASI']]$town_hs_bac)),"SCHEIA",data[['IASI']]$town_hs_bac)
    data[['IASI']]$town_hs_bac<-if_else((grepl("PASCANI",data[['IASI']]$town_hs_bac)),"PASCANI",data[['IASI']]$town_hs_bac)
    data[['IASI']]$town_hs_bac<-if_else((grepl("TARGU FRUMOS",data[['IASI']]$town_hs_bac)),"TARGU FRUMOS",data[['IASI']]$town_hs_bac)
    data[['IASI']]$town_hs_bac<-if_else((grepl("NICOLINA",data[['IASI']]$town_hs_bac)),"IASI",data[['IASI']]$town_hs_bac)
    
    data[['IALOMITA']]$town_hs_bac<-if_else((grepl("FIERBINTI",data[['IALOMITA']]$town_hs_bac)),"FIERBINTI",data[['IALOMITA']]$town_hs_bac)
    data[['IALOMITA']]$town_hs_bac<-if_else(grepl("ORTODOX",data[['IALOMITA']]$unitate_de_invatamant) & grepl("IOAN GURA DE AUR",data[['IALOMITA']]$unitate_de_invatamant),"SLOBOZIA",data[['IALOMITA']]$town_hs_bac)
    
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("TRANSPORTURI AUTO",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("GHEORGHE TITEICA",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("COLEGIUL NATIONAL \"TRAIAN\"",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("THEODOR COSTESCU",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("STEFAN ODOBLEJA",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("DECEBAL",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("TUDOR",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("SERBAN CIOCULESCU",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("DIERNA",data[['MEHEDINTI']]$unitate_de_invatamant),"ORSOVA",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("PAULIAN",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("IONESCU",data[['MEHEDINTI']]$unitate_de_invatamant),"SISESTI",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("VLADIMIRESCU",data[['MEHEDINTI']]$unitate_de_invatamant),"TUDOR VLADIMIRESCU",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("PAULIAN",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("CONSTANTIN",data[['MEHEDINTI']]$unitate_de_invatamant),"BAIA DE ARAMA",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("BASARAB",data[['MEHEDINTI']]$unitate_de_invatamant),"STREHAIA",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("GOMOIU",data[['MEHEDINTI']]$unitate_de_invatamant),"VANJU MARE",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("LALESCU",data[['MEHEDINTI']]$unitate_de_invatamant),"ORSOVA",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("SALAGEAN",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("INDUSTRIAL DE MARINA",data[['MEHEDINTI']]$unitate_de_invatamant),"ORSOVA",data[['MEHEDINTI']]$town_hs_bac)
    data[['MEHEDINTI']]$town_hs_bac<-if_else(grepl("AUTO",data[['MEHEDINTI']]$unitate_de_invatamant),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_bac)
    
    
    data[['MURES']]$town_hs_bac<-if_else(grepl("ROMANO-AMERICANA",data[['MURES']]$unitate_de_invatamant),"TARGU-MURES",data[['MURES']]$town_hs_bac)#2014
    data[['MURES']]$town_hs_bac<-if_else(grepl("JEBELEAN",data[['MURES']]$unitate_de_invatamant),"SANNICOLAU-MARE",data[['MURES']]$town_hs_bac)#2014
    data[['MURES']]$town_hs_bac<-if_else(grepl("TARGU-MURES",data[['MURES']]$unitate_de_invatamant),"TARGU MURES",data[['MURES']]$town_hs_bac)#2014
    
    
    data[['NEAMT']]$town_hs_bac<-if_else(grepl("VASILE CONTA",data[['NEAMT']]$unitate_de_invatamant),"TARGU NEAMT",data[['NEAMT']]$town_hs_bac)
    data[['NEAMT']]$town_hs_bac<-if_else(grepl("MANASTIREA NEAMT",data[['NEAMT']]$unitate_de_invatamant),"VANATORI NEAMT",data[['NEAMT']]$town_hs_bac)
    data[['NEAMT']]$town_hs_bac<-if_else(grepl("BOLINTIN",data[['NEAMT']]$unitate_de_invatamant),"BOLINTIN-VALE",data[['NEAMT']]$town_hs_bac)
    data[['NEAMT']]$town_hs_bac<-if_else(grepl("ION CREANGA",data[['NEAMT']]$unitate_de_invatamant) & grepl('COLEGIUL TEHNIC',data[['NEAMT']]$unitate_de_invatamant),"TARGU NEAMT",data[['NEAMT']]$town_hs_bac)
    
    data[['PRAHOVA']]$town_hs_bac<-if_else(grepl("BOLDESTI",data[['PRAHOVA']]$unitate_de_invatamant),"BOLDESTI-SCAENI",data[['PRAHOVA']]$town_hs_bac)
    data[['PRAHOVA']]$town_hs_bac<-if_else(grepl("MANECIU",data[['PRAHOVA']]$unitate_de_invatamant),"MANECIU",data[['PRAHOVA']]$town_hs_bac)
    data[['PRAHOVA']]$town_hs_bac<-if_else(grepl("CIORANI",data[['PRAHOVA']]$unitate_de_invatamant),"CIORANI",data[['PRAHOVA']]$town_hs_bac)
    
    
    data[['SALAJ']]$town_hs_bac<-if_else(grepl("CSEREY-GOGA",data[['SALAJ']]$unitate_de_invatamant),"CRASNA",data[['SALAJ']]$town_hs_bac)
    data[['SALAJ']]$town_hs_bac<-if_else(grepl("SIG",data[['SALAJ']]$town_hs_bac),"SAG",data[['SALAJ']]$town_hs_bac)
    
    data[['SATU-MARE']]$town_hs_bac<-if_else((grepl("SATU MARE",data[['SATU-MARE']]$unitate_de_invatamant)),"SATU MARE",data[['SATU-MARE']]$town_hs_bac)
    
    data[['SIBIU']]$town_hs_bac<-if_else((grepl("CIBINIUM",data[['SIBIU']]$unitate_de_invatamant)),"SIBIU",data[['SIBIU']]$town_hs_bac)
    data[['SIBIU']]$town_hs_bac<-if_else((grepl("COPSA MICA",data[['SIBIU']]$unitate_de_invatamant)),"COPSCA MICA",data[['SIBIU']]$town_hs_bac)
    data[['SIBIU']]$town_hs_bac<-if_else((grepl("AVRIG",data[['SIBIU']]$unitate_de_invatamant)),"AVRIG",data[['SIBIU']]$town_hs_bac)
    
    data[['SUCEAVA']]$town_hs_bac<-if_else((grepl("CENTRUL DE STUDII STEFAN CEL MARE SI SFANT",data[['SUCEAVA']]$town_hs_bac)),"SUCEAVA",data[['SUCEAVA']]$town_hs_bac)
    data[['SUCEAVA']]$town_hs_bac<-if_else(grepl("MOLDOVENESC",data[['SUCEAVA']]$unitate_de_invatamant),"CAMPULUNG MOLDOVENESC",data[['SUCEAVA']]$town_hs_bac)
    data[['SUCEAVA']]$town_hs_bac<-if_else(grepl("PIRTESTII",data[['SUCEAVA']]$unitate_de_invatamant),"PARTESTII DE JOS",data[['SUCEAVA']]$town_hs_bac)
    
    data[['TELEORMAN']]$town_hs_bac<-if_else(grepl("ALEXANRIA",data[['TELEORMAN']]$unitate_de_invatamant),"ALEXANDRIA",data[['TELEORMAN']]$town_hs_bac)
    data[['TELEORMAN']]$town_hs_bac<-if_else(grepl("DRAGANESTI",data[['TELEORMAN']]$unitate_de_invatamant),"DRAGANESTI-VLASCA",data[['TELEORMAN']]$town_hs_bac)
    data[['TELEORMAN']]$town_hs_bac<-if_else(grepl("ROSIORI",data[['TELEORMAN']]$unitate_de_invatamant),"ROSIORII DE VEDE",data[['TELEORMAN']]$town_hs_bac)
    
    data[['VASLUI']]$town_hs_bac<-if_else(grepl("BIRLAD",data[['VASLUI']]$unitate_de_invatamant),"BARLAD",data[['VASLUI']]$town_hs_bac)
    
    data[['TIMIS']]$town_hs_bac<-sub(' TIMIS$',"",data[['TIMIS']]$town_hs_bac)
    data[['TIMIS']]$town_hs_bac<-if_else(grepl("TIMISOARA",data[['TIMIS']]$unitate_de_invatamant),"TIMISOARA",data[['TIMIS']]$town_hs_bac)
    data[['TIMIS']]$town_hs_bac<-if_else(grepl("JEBELEAN",data[['TIMIS']]$unitate_de_invatamant),"SANNICOLAU MARE",data[['TIMIS']]$town_hs_bac)
    data[['TIMIS']]$town_hs_bac<-if_else(grepl("SHAKESPEARE",data[['TIMIS']]$unitate_de_invatamant),"TIMISOARA",data[['TIMIS']]$town_hs_bac)
    data[['TIMIS']]$town_hs_bac<-if_else(grepl("BILED",data[['TIMIS']]$unitate_de_invatamant),"BILED",data[['TIMIS']]$town_hs_bac)
    
    data[['VALCEA']]$town_hs_bac<-if_else( data[['VALCEA']]$town_hs_bac=="","RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( is.na(data[['VALCEA']]$town_hs_bac),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("BUZESCU",data[['VALCEA']]$unitate_de_invatamant),"BERBESTI",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("IUSTINIAN",data[['VALCEA']]$unitate_de_invatamant),"BAILE OLANESTI",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("OLANESTI",data[['VALCEA']]$unitate_de_invatamant),"BAILE OLANESTI",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("SF NICOLAE",data[['VALCEA']]$unitate_de_invatamant),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("SFANTU NICOLAE",data[['VALCEA']]$unitate_de_invatamant),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("MATEI BASARAB",data[['VALCEA']]$unitate_de_invatamant),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("GHEORGHE SURDU",data[['VALCEA']]$unitate_de_invatamant),"BREZOI",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("BRATIANU",data[['VALCEA']]$unitate_de_invatamant),"DRAGASANI",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("TARNEA",data[['VALCEA']]$unitate_de_invatamant),"BABENI",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("BABENI",data[['VALCEA']]$unitate_de_invatamant),"BABENI",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("OLTCHIM",data[['VALCEA']]$unitate_de_invatamant),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("FERDINAND",data[['VALCEA']]$unitate_de_invatamant),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else( grepl("RM",data[['VALCEA']]$unitate_de_invatamant),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    data[['VALCEA']]$town_hs_bac<-if_else(grepl("VICTOR GIUREANU",data[['VALCEA']]$unitate_de_invatamant),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_bac)
    
    
    data[['VRANCEA']]$town_hs_bac<-if_else(data[['VRANCEA']]$judet_bac=='VRANCEA' & grepl("ASACHI",data[['VRANCEA']]$unitate_de_invatamant),"FOCSANI",data[['VRANCEA']]$town_hs_bac)
    
    data<-do.call("rbind",data)
    
    #ADJUSTMENTS BY TOWN NAME
    data$town_hs_bac<-if_else(grepl("CLUJ-NAPOCA",data$unitate_de_invatamant),"CLUJ-NAPOCA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl("RAMNICU VALCEA",data$unitate_de_invatamant),"RAMNICU VALCEA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl("PITESTI",data$unitate_de_invatamant),"PITESTI",data$town_hs_bac)
     data$town_hs_bac<-if_else((grepl("ORADEA",data$town_hs_bac)),"ORADEA",data$town_hs_bac)
    data$town_hs_bac<-if_else((grepl("BIRLAD",data$town_hs_bac)),"BIRLAD",data$town_hs_bac)
    data$town_hs_bac<-if_else((grepl("T. VLADIMIRESCU",data$town_hs_bac)),"TUDOR VLADIMIRESCU",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl("OCNA-MURES",data$town_hs_bac),"OCNA MURES",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl("SINNICOLAU",data$town_hs_bac)|grepl("SANNICOLAU",data$town_hs_bac),"SANNICOLAU-MARE",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl("SINMARTIN",data$town_hs_bac),"SANMARTIN",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl("HALINGA",data$town_hs_bac),"HALANGA",data$town_hs_bac)
    data$town_hs_bac<-if_else(grepl("PIATRA NEAMT",data$town_hs_bac),'PIATRA-NEAMT',data$town_hs_bac)
    
    
    data$town_hs_bac<-if_else(grepl("BAIAMARE",data$town_hs_bac),"BAIA MARE",data$town_hs_bac)
    
    data$town_hs_bac<-if_else(data$town_hs_bac=='TG MURES','TARGU MURES',data$town_hs_bac)
    data$town_hs_bac<-if_else(data$town_hs_bac=='NEGRESTI OAS','NEGRESTI-OAS',data$town_hs_bac)
    data$town_hs_bac<-if_else(data$town_hs_bac=='TG-JIU','TARGU-JIU',data$town_hs_bac)
    data$town_hs_bac<-if_else(data$town_hs_bac=='TG JIU','TARGU-JIU',data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='BUCUREȘTI','BUCURESTI',data$town_hs_bac)
    data$town_hs_bac<-if_else(data$judet_bac=='BUCURESTI','BUCURESTI',data$town_hs_bac)
    data$town_hs_bac<-gsub('CIMPULUNG','CAMPULUNG',data$town_hs_bac)
    data$town_hs_bac<-gsub('CHISINEU CRIS','CHISINEU-CRIS',data$town_hs_bac)
    data$town_hs_bac<-gsub('TG\\. FRUMOS','TARGU FRUMOS',data$town_hs_bac)
    data$town_hs_bac<-gsub('RIMNICU','RAMNICU',data$town_hs_bac)
    data$town_hs_bac<-gsub('RM\\.','RAMNICU',data$town_hs_bac)
    data$town_hs_bac<-gsub("TIRGU","TARGU",data$town_hs_bac)
    data$town_hs_bac<-gsub("SFINTU","SFANTU",data$town_hs_bac)
    data$town_hs_bac<-gsub("TIRG","TARG",data$town_hs_bac)
    data$town_hs_bac<-gsub("SFANTUL GHEORGHE","SFANTU GHEORGHE",data$town_hs_bac)
    data$town_hs_bac<-if_else(data$town_hs_bac=='CLUJ','CLUJ-NAPOCA',data$town_hs_bac)

    data$town_hs_bac<-if_else(data$town_hs_bac=='CURTEA DE AG','CURTEA DE ARGES',data$town_hs_bac)
    
    
    #SUB TG. AND SF
    data$town_hs_bac<-sub("TG\\.","TARGU",data$town_hs_bac)
    data$town_hs_bac<-sub("SF\\.","SFANTU",data$town_hs_bac)
    
    #FINAL ADJUSTMENTS
    data$town_hs_bac<-sub("PARTICULAR","",data$town_hs_bac)
    data$town_hs_bac<-trimws(data$town_hs_bac)
    
    data_full<-data_full %>% select(-town_hs_bac)
    data_full<-base::merge(data_full,data,by=c("judet_bac","an","unitate_de_invatamant"))
    
    data_full<-data_full %>% 
      mutate(town_hs_bac=if_else(unitate_de_invatamant=='NO HS MATCHED' & liceu_repartizat=='','NOT ADMITTED',town_hs_bac)) %>%
      mutate(town_hs_bac=if_else(unitate_de_invatamant=='NO HS MATCHED' & liceu_repartizat!='','NO HS MATCHED',town_hs_bac)) 
    
    

    
    
    #TESTS:
    #1. COUNTIES, TOWNS AND NUMBER OF STUDENTS
    #test<-data_bac_raw %>% group_by(judet_bac,town_hs_bac) %>% summarize(n=n()) %>% arrange(judet_bac,n)
    #2. DEBUG: ALL DATA WITH TOWNS THAT CONTAIN SPECIFIC PATTERN
    #test2<-data_bac_raw[grepl("MESERII",data_bac_raw$town_hs_bac),]
    #2.1 DEBUG: ALL DATA WITH TOWNS THAT CONTAIN SPECIFIC PATTERN IN CERTAIN COUNTY
    #test2<-data_bac_raw[grepl("COOPERATIE",data_bac_raw$unitate_de_invatamant) & data_bac_raw$judet_bac=="BOTOSANI",]
    #3. DATA WITHOUT TOWN
    #test2<-data_bac_raw[is.na(data_bac_raw$town_hs_bac) & !is.na(data_bac_raw$nume),] %>% group_by(unitate_de_invatamant) %>%
    #  summarize(n=n())
    
    return(data_full)
  }